<?php

class Core_Backend_Component_Customer_View_Showroom_Certificate_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('index'), $this->__('share.button.back'));
        parent::buildToolbar($toolbar);
        if($this->getIdentity()->isAllowAction('customer_showroom_certificate_delete')){
	        $group = $toolbar->createGroup();
	        $group->addLink($this->getUrl(array('id' => $this->getShowroom()->getId()), 'certificate-generate'), $this->__('share.button.generate'));
	            $group->addButton($this->__('share.button.delete'))
	                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(NULL, 'certificate-delete') . "')");
        }
    }

    protected function buildGrid($grid) {
        $grid->setId('grid')
                ->setPrimaryKey('id');
        $grid->addLabelColumn($this->__('customer.label.code'), 'code', '{code}')
        		->setWidth(100);
        $grid->addDatetimeColumn($this->__('customer.label.expiry_date'), 'expiry_date', '{expiry_date}');
        $grid->addLabelColumn($this->__('customer.label.access_times'), 'access_times', '{access_times}')
                ->setAlign('center')
                ->setWidth(60);
        $grid->addLabelColumn($this->__('customer.label.mender'), 'mender', '{mender}')
                ->setWidth(60);
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'certificate-edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        if($this->getIdentity()->isAllowAction('customer_showroom_certificate_delete')){
	        $grid->addLinkColumn('#', 'delete', $this->getUrl(array('ids[]' => '{id}'), 'certificate-delete'), $this->__('share.button.delete'))
	                ->setWidth(40)
	                ->setAlign('center');
        }
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        parent::buildPagination($pagination);
        $pagination->setUrlFormat($this->getPaginationUrl())
                ->setRecordCount($this->getRecords());
    }

}